package com.rgs.se.data.stack;

import java.util.ArrayList;

/**
 * @author Ren Gaoshuai
 * @ClassName Test01
 * 括号匹配
 * @date 2022-04-03 22:06
 **/
public class Test01{
    
    
    public static boolean solution(String str){
        char[] chars = str.toCharArray();
        ArrayStack<Character> stack = new ArrayStack<>();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '(' || chars[i] =='[' || chars[i] == '{'){
                stack.push(chars[i]);
            }else{

                switch (chars[i]){
                    case ')': {
                        Character pop = stack.pop();
                        if (pop != '(') return false;
                        continue;
                    }
                    case ']' :{
                        Character pop = stack.pop();
                        if (pop != '[') return false;
                        continue;
                    }
                    case '}' :{
                        Character pop = stack.pop();
                        if (pop != '{') return false;
                        continue;
                    }
                    default:
                        return false;
                }
            }
//            if (chars[i] == ')'){
//                Character pop = stack.pop();
//                if (pop != '('){
//                    return false;
//                }
//                continue;
//            }
//            if (chars[i] == ']'){
//                Character pop = stack.pop();
//                if (pop != '['){
//                    return false;
//                }
//                continue;
//            }
//            if (chars[i] == '}'){
//                Character pop = stack.pop();
//                if (pop != '{'){
//                    return false;
//                }
//                continue;
//            }
        }
        return true;
    }

    public static void main(String[] args){
        System.out.println(solution("[[[}}}[[[}}"));
        System.out.println(solution("{()}[]{{()}}"));


    }
}
